//
//  RepairHistoryDetailHeaderCell.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14/11/13.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "ComplaintDetailHeaderCell.h"
#import "UIImageView+WebCache.h"
@implementation ComplaintDetailHeaderCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _titleLabel = [self createLabelWithFrame:CGRectMake(10, 10, 200, 20) text:@"" font:15 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [self.contentView addSubview:_titleLabel];
    
    _subtitleLabel = [self createLabelWithFrame:CGRectMake(_titleLabel.left, _titleLabel.bottom+3, 300, 20) text:@"" font:14 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [self.contentView addSubview:_subtitleLabel];
    
    _fontImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, _subtitleLabel.bottom+5, SCREEN_WIDTH-20*2, 150)];
    [self.contentView addSubview:_fontImageView];
    
    _preImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, _fontImageView.bottom+5, SCREEN_WIDTH-20*2, 150)];
    [self.contentView addSubview:_preImageView];
}

-(void)setData:(NSDictionary *)data{
    
    if(_data != data){
        _data = data;
        NSString* title = ObjToString(data[@"title"]);
        _titleLabel.text = title;
        
        NSString* subtitle = ObjToString(data[@"subtitle"]);
        _subtitleLabel.text = subtitle;
        
        NSArray* images = data[@"images"];
        NSString* status = ObjToString(data[@"status"]);
        NSString* image1 = images[0];
        [_fontImageView setImageWithURL:[NSURL URLWithString:image1]];
        if(status.intValue == 2){
            NSString* iamge2 = images[1];
            [_preImageView setImageWithURL:[NSURL URLWithString:iamge2]];
            
            UILabel* label = [self createLabelWithFrame:CGRectMake(-20, 20, 50, 15) text:@"处理前" font:13 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
            [label setBackgroundColor:MAIN_BLUE_COLOR];
            
            UILabel* label1 = [self createLabelWithFrame:CGRectMake(-20, 20, 50, 15) text:@"处理后" font:13 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
            [label1 setBackgroundColor:MAIN_BLUE_COLOR];
            
            [_fontImageView addSubview:label];
            [_preImageView addSubview:label1];
            
            [_fontImageView sendSubviewToBack:label];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

@end
